package com.skyline.base.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.view.RedirectView;

import com.skyline.common.util.Constant;
import com.skyline.user.model.User;

/**
 * 
 * @author Jairus Chan
 */
@Controller
@RequestMapping("/")
public class IndexController {

	private static RedirectView myWoRV = new RedirectView("/skyline/wo/myWo.html");
	private static RedirectView loginRV = new RedirectView("/skyline/login.html");

	/**
	 * 用于跳转到index页
	 * @param httpServletRequest
	 * @return
	 */
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public RedirectView gotoIndex(HttpServletRequest httpServletRequest) {
		RedirectView rv = null;
		HttpSession session = httpServletRequest.getSession();
		User u = (User) session.getAttribute(Constant.SESSION_USER);
		
		if (u == null || u.getId() == 0) {
			rv = loginRV;
		} else {
			rv = myWoRV;
		}
		
		return rv;
	}
}
